package com.czmh.etc.onlinepubsys.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;

/**
 * @描述：微信相关初始化配置
 * @author： Seven.
 * @创建日期：Oct 22, 2019 3:26:25 PM.
 * @版本：1.0.0
 */
@Configuration
public class WxConfiguration {
	@Value("${wx.appid}")
	private String appId;
	@Value("${wx.appSecret}")
	private String appsecret;
	@Value("${wx.token}")
	private String token;
	@Value("${wx.encodingAESKey}")
	private String encodingAESKey;
	
	@Bean
	public WxMpDefaultConfigImpl wxConfig() {
	    WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
		config.setAppId(appId); // 设置微信公众号的appid
		config.setSecret(appsecret); // 设置微信公众号的app corpSecret
		config.setToken(token); // 设置微信公众号的token
		config.setAesKey(encodingAESKey); // 设置微信公众号的EncodingAESKey
		return config;
	}
	
	@Bean
	public WxMpService initWxMpService() {
		WxMpService wxService = new WxMpServiceImpl();
		wxService.setWxMpConfigStorage(wxConfig());
		return wxService;
	}
	
	@Bean(name = {"router"})
	public WxMpMessageRouter initWxMpMessageRouter() {
		return new WxMpMessageRouter(initWxMpService());
	}
}
